package util;

import org.hibernate.SessionFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;

public class SessionFactorySetterListener extends AbstractTestExecutionListener {
	private static ThreadLocal<SessionFactory> sessionFactory = new ThreadLocal<SessionFactory>();

	@Override
	public void beforeTestClass(TestContext testContext) {
		sessionFactory.set(((GenericApplicationContext) testContext
				.getApplicationContext()).getBean(SessionFactory.class));
	}

	@Override
	public void afterTestClass(TestContext testContext) {
		//
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory.get();
	}
}
